import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "../../CMDSender.js" as Controler

Item {
    id:root
    width:parent.width
    height:parent.height

    opacity: 0
    Component.onCompleted: {
        opacity=1;
    }
    Behavior on opacity {
        PropertyAnimation{
            properties: "opacity"
            duration: 500
        }
    }

    //datas
    property int temp:22
    property string mode:"自动"
    property string speed:"自动"

    //air state screen pad
    Image{
        id:airScreenPad
        source:"qrc:/imgs/control/smartHomeIcons/control/screen_air_state_pad.png"
        anchors.horizontalCenter: parent.horizontalCenter
        y:35*Device.dentisty
        width: parent.width*5/6
        height:width*sourceSize.height/sourceSize.width

        Text{
            anchors.horizontalCenter: parent.horizontalCenter
            y:5*Device.dentisty
            text:temp+"℃"
            font.pointSize: 25
            color:"#12aadf"
        }

        //temp

        //left
        Image {
            id: speedShower
            source: "qrc:/imgs/control/smartHomeIcons/control/screen_air_left_pad.png"
            anchors.verticalCenter: parent.verticalCenter
            Text{
                anchors.centerIn: parent
                text:speed
                font.pointSize: 25
                color:"#12aadf"
            }
        }

        //right
        Image {
            id: modeShower
            source: "qrc:/imgs/control/smartHomeIcons/control/screen_air_right_pad.png"
            anchors.verticalCenter: parent.verticalCenter
            anchors.right: parent.right
            Text{
                anchors.centerIn: parent
                text:mode
                font.pointSize: 25
                color:"#12aadf"
            }
        }
    }

    //switcher
    Switch{
        id:airconditionerSwitcher
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top:airScreenPad.bottom
        anchors.topMargin: 20*Device.dentisty
        checked: powerOn
        onCheckedChanged:{
//            lightModel.setProperty(index,"powerOn",checked);
            if(checked){
                if(TcpSocket.tcpState==="connected")
                    TcpSocket.sendData("air_01_power_on#!");
                else
                    Controler.send("air_01_power_on");
            }
            else{
                if(TcpSocket.tcpState==="connected")
                    TcpSocket.sendData("air_01_power_off#!");
                else
                    Controler.send("air_01_power_off");
            }

        }

        style:SwitchStyle{
            groove: Image {
                source:control.checked?"qrc:/imgs/control/smartHomeIcons/control/switcher_on.png":
                                        "qrc:/imgs/control/smartHomeIcons/control/switcher_off.png"
            }
            handle: Image{
                source:"qrc:/imgs/control/smartHomeIcons/control/switcher_drigger.png"
            }
        }

    }

    //temp controller bnt
    Column{
        id:tempControlBnts
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: airconditionerSwitcher.bottom
        anchors.topMargin: 30*Device.dentisty
        spacing: 50*Device.dentisty
        //temp up
        Image {
            id: tempUpBnt
            source: "qrc:/imgs/control/smartHomeIcons/control/bnt_air_tem_up.png"
            width: 50*Device.dentisty
            height:width
            Rectangle{
                anchors.fill: parent
                color:"#33000000"
                radius: 5*Device.dentisty
                id:tempUpcap
                opacity: 0
            }

            MouseArea{
                anchors.fill: parent
                onEntered: tempUpcap.opacity=1;
                onExited: tempUpcap.opacity=0;
                onClicked: {
                    if(TcpSocket.tcpState==="connected")
                        TcpSocket.sendData("air_01_temp_up#!");
                    else
                        Controler.send("air_01_temp_up");
                }
            }
        }

        //temp down
        Image {
            id: tempDownBnt
            source: "qrc:/imgs/control/smartHomeIcons/control/bnt_air_tem_down.png"
            width: 50*Device.dentisty
            height:width
            Rectangle{
                anchors.fill: parent
                color:"#33000000"
                radius: 5*Device.dentisty
                id:tempDowncap
                opacity: 0
            }

            MouseArea{
                anchors.fill: parent
                onEntered: tempDowncap.opacity=1;
                onExited: tempDowncap.opacity=0;
                onClicked: {
                    if(TcpSocket.tcpState==="connected")
                        TcpSocket.sendData("air_01_temp_down#!");
                    else
                        Controler.send("air_01_temp_down");
                }
            }
        }
    }

    //mode and speed bnts
    Row{
        id:modeAndSpeedBnts
        anchors.centerIn: tempControlBnts
        spacing: 80*Device.dentisty

        //speed switcher
        Image {
            id: speedBnt
            source: "qrc:/imgs/control/smartHomeIcons/control/bnt_air_speed_switch.png"
            Rectangle{
                anchors.fill: parent
                color:"#33000000"
                radius: height/2
                id:speedcap
                opacity: 0
            }

            MouseArea{
                anchors.fill: parent
                onEntered: speedcap.opacity=1;
                onExited: speedcap.opacity=0;
                onClicked: {
                    if(TcpSocket.tcpState==="connected")
                        TcpSocket.sendData("air_01_fan_speed_switch#!");
                    else
                        Controler.send("air_01_fan_speed_switch");
                }
            }
        }

        //mode switcher
        Image {
            id: modeBnt
            source: "qrc:/imgs/control/smartHomeIcons/control/bnt_air_mdoe_switch.png"
            Rectangle{
                anchors.fill: parent
                color:"#33000000"
                radius: height/2
                id:modecap
                opacity: 0
            }

            MouseArea{
                anchors.fill: parent
                onEntered: modecap.opacity=1;
                onExited: modecap.opacity=0;
                onClicked: {
                    if(TcpSocket.tcpState==="connected")
                        TcpSocket.sendData("air_01_mode_switch#!");
                    else
                        Controler.send("air_01_mode_switch");
                }
            }
        }
    }
}
